import java.util.ArrayList;
import java.util.List;

/**
 * @author zyj
 * @date 2022年06月09日 14:25
 */
public class ThreadLocalDemo {
    public static void main(String[] args) {
        ThreadLocal<String> list = new ThreadLocal<>();
        new ThreadB(list).start();
        new ThreadB(list).start();
    }
}

class ThreadB extends Thread{
    private ThreadLocal<String> list;

    ThreadB(ThreadLocal<String> list){
        this.list = list;
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            list.set(Thread.currentThread().getName() + ":" + i);
            System.out.println(list.get());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
